﻿using ERP.ERPSystem.DataAnalysis;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace ERP.Web.Controllers.DataAnalysis
{
    /// <summary>
    /// 物料入库对比图
    /// </summary>
    [Route("[controller]")]
    public class IInboundCmparisonController : Controller
    {
        private readonly IInboundCmparisonServices inboundCmparisonServices;

        public IInboundCmparisonController(IInboundCmparisonServices inboundCmparisonServices)
        {
            this.inboundCmparisonServices = inboundCmparisonServices;
        }

        /// <summary>
        /// 物料入库对比的视图
        /// </summary>
        /// <returns></returns>
        [Route("")]
        [Route("Index")]
        [Route("InboundCmparison")]
        public IActionResult InboundCmparison()
        {
            return View("~/Views/IInboundCmparison/InboundCmparison.cshtml");
        }

        /// <summary>
        /// 获取入库出库趋势数据API
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [Route("GetTrendData")]
        public async Task<JsonResult> GetTrendData(DateTime? startDate = null, DateTime? endDate = null)
        {
            try
            {
                var result = await inboundCmparisonServices.GetInboundOutboundTrendAsync(startDate, endDate);
                return Json(new { success = true, data = result });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取入库出库汇总数据API
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [Route("GetSummaryData")]
        public async Task<JsonResult> GetSummaryData(DateTime? startDate = null, DateTime? endDate = null)
        {
            try
            {
                var result = await inboundCmparisonServices.GetInboundOutboundSummaryAsync(startDate, endDate);
                return Json(new { success = true, data = result });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取详细统计数据API
        /// </summary>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [Route("GetDetailData")]
        public async Task<JsonResult> GetDetailData(DateTime? startDate = null, DateTime? endDate = null)
        {
            try
            {
                var result = await inboundCmparisonServices.GetInboundOutboundDetailAsync(startDate, endDate);
                return Json(new { success = true, data = result });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取库存柱状图数据API
        /// </summary>
        /// <returns></returns>
        [Route("GetInventoryBarData")]
        public async Task<JsonResult> GetInventoryBarData()
        {
            try
            {
                var result = await inboundCmparisonServices.GetInventoryBarDataAsync();
                return Json(new { success = true, data = result });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }

        /// <summary>
        /// 获取库存趋势折线图数据API
        /// </summary>
        /// <returns></returns>
        [Route("GetInventoryTrendData")]
        public async Task<JsonResult> GetInventoryTrendData()
        {
            try
            {
                var result = await inboundCmparisonServices.GetInventoryTrendDataAsync();
                return Json(new { success = true, data = result });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, message = ex.Message });
            }
        }
    }
}
